#include <iostream>
#include <vector>

int check(std::vector<int> &num_vec)
{
    int num = 0;
    for (int i = 0; i < num_vec.size(); i++)
    {
        num += num_vec[i];
    }

    if (num < 100 || num > 999)
        return -1;

    int a = num / 100;
    int b = (num % 100) / 10;
    int c = num % 10;

    if (a * a * a + b * b * b + c * c * c == num)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

void find(std::vector<int> &arr, std::vector<std::vector<int>> &curr_arr, std::vector<std::vector<std::vector<int>>> &seg_arr)
{
    if (arr.size() == 0)
    {
        seg_arr.push_back(curr_arr);
        return;
    }

    for (int i = 1; i <= arr.size(); i++)
    {
        std::vector<int> curr(arr.begin(), arr.begin() + i);
        if (check(curr) == 1)
        {
            curr_arr.push_back(curr);
            std::vector<int> rem(arr.begin() + i, arr.end());
            find(rem, curr_arr, seg_arr);
            curr_arr.pop_back();
        }
    }
}

int main()
{
    std::string istr;
    std::cin >> istr;

    std::vector<int> arr;
    for (int i = 0; i < istr.size(); i++)
    {
        arr.push_back(int(istr[i]));
    }

    std::vector<std::vector<int>> curr_arr;
    std::vector<std::vector<std::vector<int>>> seg_arr;
    find(arr, curr_arr, seg_arr);

    int cnt = seg_arr.size();
    if (cnt == 0)
    {
        std::cout << 0 << std::endl;
    }
    else if (cnt > 1)
    {
        std::cout << -1 << std::endl;
    }
    else
    {
        std::cout << seg_arr[0].size() << std::endl;
        // for (int i = 0; i < seg_arr[0].size(); i++)
        // {
        //     for (int j = 0; j < seg_arr[0][i].size(); j++)
        //     {
        //         std::cout << (char)seg_arr[0][i][j];
        //     }
        //     std::cout << std::endl;
        // }
    }
    return 0;
}